package mtn.bowen.yan.server.utils;

import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @author <a href=mailto:yanbowen90@foxmail.com> bowen.yan </a>
 * @version 1.0
 * @description: TODO
 * @date 2021-10-28 9:01 PM
 */
@Component
public class LoadingUtils {

    private final static Logger LOGGER = LoggerFactory.getLogger(ResourceBundleUtil.class);

    public Parent loadingDefault(StackPane container) {
        try {
            Region loadDefault = FXMLLoader.load(getClass().getResource("/template/module/loading/loading-default.fxml"));
            container.getChildren().add(loadDefault);
            return loadDefault;
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error("LoadingUtils.loadingDefault is error", e);
        }
        return null;
    }

    public void remove(StackPane container, Parent parent) {
        container.getChildren().remove(parent);
    }

    public Parent loading(StackPane container) {
        try {
            Region loadDefault = FXMLLoader.load(getClass().getResource("/template/module/loading/loading.fxml"));
            container.getChildren().add(loadDefault);
            return loadDefault;
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error("LoadingUtils.loadingDefault is error", e);
        }
        return null;
    }
}
